package everyday;

import java.util.Arrays;

public class T1626 {
    public int bestTeamScore(int[] scores, int[] ages) {
        int res = 0;
        int len=scores.length;
        int[][] people=new int[len][2];
        int []dp=new int[len];
        for (int i = 0; i <len ; i++) {
            people[i]=new int[]{scores[i],ages[i]};
        }
        Arrays.sort(people,(a,b)->a[0]!=b[0]?a[0]-b[0]:a[1]-b[1]);

        for (int i = 0; i < len; i++) {
            for (int j = i-1; j >=0; j--) {
                if (people[j][1]<=people[i][1]){
                    dp[i]=Math.max(dp[i],dp[j]);
                }
            }
            dp[i]+=people[i][0];
            res=Math.max(res,dp[i]);
        }
        return res;

    }

}
